package com.glodon.paas.document.dao.domain;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.glodon.paas.document.api.bean.ProjectRole;
import com.glodon.paas.document.service.util.DocumentBuilder;
import com.glodon.paas.util.BeanFactoryUtil;
import com.google.code.morphia.annotations.Entity;
import com.google.code.morphia.annotations.Id;

@Entity(value = "file", noClassnameStored = true)
public class ProjectRoleEntity {

    public static DocumentBuilder builder = null;

    public static ProjectRole getDto(ProjectRoleEntity e) {
        return getDto(e, false);
    }

    public static ProjectRole getDto(ProjectRoleEntity e, boolean cascade) {
        if (e == null) {
            return null;
        } else {
            ProjectRole d = new ProjectRole();
            d.setId(e.getId());
            d.setCreateTime(e.getCreateTime());
            d.setDeleted((e.getIsDeleted() == null ? 0 : e.getIsDeleted()) == 1);
            d.setProjectId(e.getProjectId());
            d.setRoleName(e.getRoleName());
            d.setUpdateTime(e.getUpdateTime());
            d.setDefault((e.getIsDefault() == null ? 0 : e.getIsDefault()) == 1);
            d.setEditable((e.getIsEditable() == null ? 0 : e.getIsEditable()) == 1);
            d.setVisible(e.getIsVisible() == 1);
            d.setMemberCount(e.getMemberCount());
            if (cascade) {
                if (e.getCreator() != null) {
                    if (builder == null) {
                        builder = BeanFactoryUtil.getBean(DocumentBuilder.class);
                    }
                    d.setCreator(builder.buildUser(e.getCreator()));
                }
            }
            return d;
        }
    }

//    public static List<ProjectRole> getDtos(List<ProjectRoleEntity> es) {
//        return getDtos(es, false);
//    }

    public static List<ProjectRole> getDtos(List<ProjectRoleEntity> es, boolean cascade) {
        if (es == null) {
            return null;
        } else {
            List<ProjectRole> ds = new ArrayList<ProjectRole>(es.size());
            for (ProjectRoleEntity e : es) {
                ds.add(getDto(e, cascade));
            }
            return ds;
        }
    }

    @Id
    private String  id;
    private String  roleName;
    private String  projectId;
    private Integer isDeleted  = 0;
    private Integer isEditable = 0;
    private Integer isVisible  = 0;
    private Date    createTime;
    private Date    updateTime;
    private String  creator;
    private String  updator;
    private Integer isDefault  = 0;
    private Integer memberCount =0;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getRoleName() {
        return roleName;
    }

    public void setRoleName(String roleName) {
        this.roleName = roleName;
    }

    public String getProjectId() {
        return projectId;
    }

    public void setProjectId(String projectId) {
        this.projectId = projectId;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public Integer getIsDeleted() {
        return isDeleted;
    }

    public void setIsDeleted(Integer isDeleted) {
        this.isDeleted = isDeleted;
    }

    public String getCreator() {
        return creator;
    }

    public void setCreator(String creator) {
        this.creator = creator;
    }

    public String getUpdator() {
        return updator;
    }

    public void setUpdator(String updator) {
        this.updator = updator;
    }

    public Integer getIsDefault() {
        return isDefault;
    }

    public void setIsDefault(Integer isDefault) {
        this.isDefault = isDefault;
    }

    public Integer getIsEditable() {
        return isEditable;
    }

    public void setIsEditable(Integer isEditable) {
        this.isEditable = isEditable;
    }

    public Integer getIsVisible() {
        return isVisible;
    }

    public void setIsVisible(Integer isVisible) {
        this.isVisible = isVisible;
    }

    public Integer getMemberCount() {
        return memberCount;
    }

    public void setMemberCount(Integer memberCount) {
        this.memberCount = memberCount;
    }
    
    public boolean isDefault(){
        return this.isDefault != null && this.isDefault.intValue() == 1;
    }
    
    public boolean isEditable(){
        return this.isEditable != null && this.isEditable.intValue() == 1;
    }
}
